package com.Service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.CommentInfo;
import com.Service.CommentService;

@Service("commentService")
public class CommentServiceImpl extends BaseServiceImpl<CommentInfo> implements
		CommentService {

	@Autowired
	private BaseDaoI<CommentInfo> commentDao;

	@Override
	public Long getCommentNum(int topicid) {

		Map<String, Object> params = new HashMap<String, Object>();
		params.put("topicId", topicid);

		String hql = "from CommentInfo t where t.topicId = :topicId";
		return commentDao.count(hql, params);

	}

	@Override
	public List<CommentInfo> findByTopicId(int topicid, int currpage,
			int pagesize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("topicId", topicid);

		String hql = "from CommentInfo t where t.topicId = :topicId order by t.commentTime ASC";
		if (commentDao.find(hql, params) != null) {
			return commentDao.find(hql, params, currpage, pagesize);
		} else {
			return null;
		}
	}

}
